﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace l1cs
{
    public class Properties_java
    {
        Dictionary<string, string> hash = new Dictionary<string, string>();

        public Properties_java( String filename )
        {

            using ( StreamReader sr = new StreamReader( new FileStream( filename, FileMode.Open ), Encoding.GetEncoding( 932 ) ) )
            {
                String line = "";
                int i;
                while ( ( line = sr.ReadLine() ) != null )
                {
                    if ( line.Length == 0 )
                    {
                        continue;
                    }
                    if ( line.StartsWith( "#" ) )
                    {
                        continue;
                    }
                    i = line.IndexOf( "=" );
                    if ( i != -1 )
                    {
                        String key = line.Substring( 0, i ).Trim();
                        String val = line.Substring( i + 1 ).Trim();

                        //_log.info("<" + key + ">=<" + val + ">");

                        hash.Add( key, val );
                    }
                }
            }

        }

        public Properties_java() { }
        public String getProperty( String key, String def )
        {
            if ( hash.ContainsKey( key ) )
            {
                return hash[key];
            }
            else
            {
                return def;
            }
        }

        public int getPropertyInt( String key, String def )
        {
            return int.Parse( getProperty( key, def ) );
        }

        public bool getPropertyBool( String key, String def )
        {
            return bool.Parse( getProperty( key, def ) );
        }

        public short getPropertyShort( String key, String def )
        {
            return short.Parse( getProperty( key, def ) );
        }

        public byte getPropertyByte( String key, String def )
        {
            return byte.Parse( getProperty( key, def ) );
        }

        public double getPropertyDouble( String key, String def )
        {
            return double.Parse( getProperty( key, def ) );
        }
    }

}
